package com.applications.codemash.utility;

import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class CustomListAdapter<T> extends BaseAdapter
{
	private Activity _activity;
	private List<T> _data;
	
	public List<T> getData() { return _data; }
	
	public CustomListAdapter(List<T> data, Activity activity, ListView view)
	{
		_data = data;
		_activity = activity;
		view.setAdapter(this);
	}
	
	@Override
	public int getCount()
	{
		return _data.size();
	}

	@Override
	public T getItem(int position)
	{
		return _data.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int index, View renderer, ViewGroup parent)
	{
		TextView view = new TextView(_activity);
		if (renderer != null)
		{
			view = (TextView) renderer;
		}
			
		view.setPadding(10, 10, 10, 10);
		view.setText(getItem(index).toString());
		view.setWidth(android.view.ViewGroup.LayoutParams.FILL_PARENT);
		return view;
	}
}
